
package kaizone.haining.chaobohui.fragment;

import kaizone.haining.chaobohui.R;
import kaizone.haining.chaobohui.activity.DetailActivity;
import kaizone.haining.chaobohui.args.AppArgs;
import kaizone.haining.chaobohui.json.Item.PicModel;
import kaizone.haining.chaobohui.util.ImageFetcher;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class NearbyFragment extends Fragment {

    private TextView mTitleTextView;

    private TextView mCopyrightTextView;

    private ImageView mImageView;

    private TextView mContentTextView;

    private ImageFetcher mImageFetcher;

    public NearbyFragment() {

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getActivity() instanceof DetailActivity) {
            mImageFetcher = ((DetailActivity) getActivity()).getImageFetcher();
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (AppArgs.sNearbyItem == null)
            return null;

        View view = (View) inflater.inflate(R.layout.news_detail, null);
        mTitleTextView = (TextView) view.findViewById(R.id.tv01);
        mCopyrightTextView = (TextView) view.findViewById(R.id.tv02);
        mContentTextView = (TextView) view.findViewById(R.id.tv03);
        mImageView = (ImageView) view.findViewById(R.id.img);

        mTitleTextView.setText(AppArgs.sNearbyItem.getName());
        mCopyrightTextView.setText(AppArgs.sNearbyItem.getGmtModified());
        mContentTextView.setText(AppArgs.sNearbyItem.getIntro());
        PicModel picModel = AppArgs.sNearbyItem.getPicModel();
        if (picModel != null) {
            mImageView.setVisibility(View.VISIBLE);
            mImageFetcher.loadImage(picModel.url, mImageView);
        }

        return view;
    }

    public static NearbyFragment newInstance() {
        final NearbyFragment f = new NearbyFragment();

        return f;
    }
}
